package com.zrf.base.knowledge.leetcode.primary;

public class DistinctSortedArray {

    public static void main(String[] args) {
        int[] a = new int[]{0, 1, 1, 2, 3, 3, 4};
        System.out.println(distinctArray(a));
    }

    public static int distinctArray(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int itemIndex = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[itemIndex] != nums[i]) {
                itemIndex++;
                nums[itemIndex] = nums[i];
            }
        }
        return itemIndex + 1;
    }
}
